package com.mdnote.jianzhi_offer.linked_list;

/**
 * @author Rhythm-2019
 * @version 1.0
 * @date 2020/10/24
 * @description 剑指 Offer 18. 删除链表的节点
 */
public class Offer18I {


    public ListNode deleteNode(ListNode head, int val) {
        if (head == null) {
            return null;
        }
        if (head.val == val) {
            return head.next;
        }
        ListNode cur = head;
        while (cur.next != null) {
            if (cur.next.val == val) {
                cur.next = cur.next.next;
                break;
            }
            cur = cur.next;
        }
        return head;
    }

     public static class ListNode {
         int val;
         ListNode next;
         ListNode(int x) { val = x; }
     }
}
